﻿#region License
// (c) Intergen.
// This source is subject to the Microsoft Public License (Ms-PL).
// Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
// All other rights reserved.
#endregion

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TextGlow.Control.Packaging
{
  public abstract class Container : IContainer
  {
    private Dictionary<string, IPackagePart> _parts = new Dictionary<string, IPackagePart>();
    private PackageRelationshipCollection _relationships;

    /// <summary>
    /// Gets the container's child parts.
    /// </summary>
    /// <value>The parts.</value>
    public IDictionary<string, IPackagePart> Parts
    {
      get { return _parts; }
    }

    /// <summary>
    /// Gets the container's relationships.
    /// </summary>
    /// <value>The relationships.</value>
    public PackageRelationshipCollection Relationships
    {
      get { return _relationships; }
      protected set { _relationships = value; }
    }

    /// <summary>
    /// Gets the child part of the given PartType.
    /// </summary>
    /// <param name="partType">Type of the part.</param>
    /// <returns></returns>
    public virtual IPackagePart GetPart(PartType partType)
    {
      return Parts.SingleOrDefault(p => p.Value.PartType == partType).Value;
    }

    /// <summary>
    /// Gets the child parts of the given PartType.
    /// </summary>
    /// <param name="partType">Type of the part.</param>
    /// <returns></returns>
    public virtual IList<IPackagePart> GetParts(PartType partType)
    {
      return Parts.Values.Where(p => p.PartType == partType).ToList();
    }

    public abstract IPackagePart CreatePart(Uri partUri, string relationshipType);

    /// <summary>
    /// Gets the container URI.
    /// </summary>
    /// <value>The URI.</value>
    public abstract Uri Uri { get; }
  }
}